#include "laserhelper.h"
#include <QDebug>


LaserHelper::LaserHelper():
   _mb_ptr{Singleton<mbControl>::get()}
{

}

//LaserHelper::LaserHelper()
//{

//}

/// 处理掉线问题
void LaserHelper::handlerDis()
{
    currentStatus.initFailed(MU_DEVICE_LASYER);
    // TaskManager::GetInstance()->setATask(MU_TASK_INDEX_CAM,false);
    pushExp(MU_Messages::Laser,MU_EXPS::EXP_LASER_DIS,MU_ERROR_MODULE_LASER,DateTime::getFullTime());
}

MU_RETURNS LaserHelper::_connect()
{
    return MU_RETURN_SUCCESS;
}

void LaserHelper::Connect()
{
    if(currentStatus.GetInit(MU_DEVICE_LASYER)){     /// 如果已经初始化了
        qWarning()<<"相机已经初始化成功!"<<__FUNCTION__;
        return ;
    }else {

    }
    currentStatus.setInitType(MU_DEVICE_LASYER,MU_TY_RUNNING);
    auto result = std::async(std::launch::async,&LaserHelper::_connect,this);


    if(MU_RETURN_SUCCESS != result.get()){
        currentStatus.initFailed(MU_DEVICE_LASYER);
        std::cout << "激光连接:" << MU_Get_Msg(result.get()) << ".\n";
        return ;
    }

    currentStatus.initSucess(MU_DEVICE_LASYER);
}

MU_RETURNS LaserHelper::Open()
{
    try {
       _mb_ptr->openLaser();
       return MU_RETURN_SUCCESS;
    } catch (...) {
        qWarning()<<"激光打开失败!"<<__FUNCTION__;
        throw MU_EXPS::EXP_LASER_FALSE;
        return MU_RETURN_ERROR;
    }
    return MU_RETURN_SUCCESS;
}

MU_RETURNS LaserHelper::Close()
{
    try {
       _mb_ptr->closeLaser();
    } catch (...) {
        qWarning()<<"激光关闭异常!"<<__FUNCTION__;
        throw MU_EXPS::EXP_LASER_FALSE;
        return MU_RETURN_ERROR;
    }
    return MU_RETURN_SUCCESS;
}
